package com.qcby.byc.demo0422.controller;

import com.qcby.byc.demo0422.entity.Depart;
import com.qcby.byc.demo0422.entity.Person;
import com.qcby.byc.demo0422.service.DepartService;
import com.qcby.byc.demo0422.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @className: Demo0512Controller
 * @description:
 * @author: lxt
 * @create: 2021-05-12 22:03
 *
 * @Controller
 * @ResponseBody
 **/
@RestController
@RequestMapping("demo0512")
public class Demo0512Controller {

    @Autowired
    private PersonService personService;


    @Autowired
    private DepartService departService;


    // @ResponseBody
    @RequestMapping //
    public List<Person> testSave(){
        List<Person> result = new ArrayList<>();
        Person person1 = new Person();
        person1.setName("lxt1");
        person1.setSex(0);
        person1.setDepartId(1L);
        personService.saveOld(person1);

        Person person2 = new Person();
        person2.setName("lxt2");
        person2.setSex(1);
        person2.setDepartId(2L);
        personService.saveNew(person2);

        result.add(person1);
        result.add(person2);
        return result;
    }

    @RequestMapping("testInsertBatch")
    public List<Person> testInsertBatch(){
        List<Person> result = new ArrayList<>();
        Person person1 = new Person();
        person1.setName("lxt1");
        person1.setSex(0);
        person1.setDepartId(1L);
        Person person2 = new Person();
        person2.setName("lxt2");
        person2.setSex(1);
        person2.setDepartId(2L);
        result.add(person1);
        result.add(person2);
        personService.insertBatch(result);
        return result;
    }

    @RequestMapping("deleteByIds")
    public List<Long> deleteByIds(@RequestParam List<Long> idList){
        personService.deleteByIds(idList);
        return idList;
    }

    @RequestMapping("listPersonNew")
    public List<Person> listPersonNew(String name){
        // ctrl+alt+b
        return  personService.listPersonNew(name);
    }

    @RequestMapping("listPersonNewM")
    public List<Person> listPersonNewM(){
        return  personService.listPersonNewM();
    }


    @RequestMapping("listAllDepartNew")
    public List<Depart> listAllDepartNew(Depart depart){
        return  departService.listAllDepartNew(depart);
    }

    /**
     * xxxx
     *
     *
     *asdasd
     *
     * @return
     */
    @RequestMapping("listAllDepartAndManager")
    public List<Depart> listAllDepartAndManager(){
        return  departService.listAllDepartAndManager();
    }

}
